import requests as rq
from bs4 import BeautifulSoup as bs
import json
import pandas as pd

DATA=[]
for page in range(160):
  
    url='https://search.damai.cn/searchajax.html?keyword=&cty=&ctl=&sctl=&tsg=0&st=&et=&order=1&pageSize=30&currPage=1&tn='.format(page)
    #
    header={'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
                'referer':'https://search.damai.cn/search.htm'    
    }

    sources=rq.get(url,headers=header)
    da=sources.text
    
    rt=json.loads(da)
    df=rt['pageData']['resultData']
    for item in df:
        dt={}
        dt['艺人']=item['actors'][3:].split('、')
        dt['城市']=item['cityname']
        dt['影票类型']=item['subcategoryname']
        dt['票价']=item['price_str']
        dt['票况']=item['showstatus']
        dt['上映时间']=item['showtime'].strip()
        dt['图片']=item['verticalPic']
        dt['演出名称']=item['name']
        print(dt)
#        dt=pd.DataFrame()
         #转化为数据框
        date=DATA.append(dt)
date=pd.DataFrame(DATA)

#    保存为excel
date.to_excel('大麦网演出数据.xlsx')
 
